package com.aos.eap.utils;

import android.util.Log;

import com.aos.eap.base.Constant;
import com.aos.eap.bean.net.BaseRequestBean;
import com.aos.eap.bean.net.HeaderBean;
import com.aos.eap.bean.net.RequestBean;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yi.zhang
 * @date 2019/9/2
 * @desc 网络请求处理类
 */
public class NetUtils {
    public static <T> void requestGetNet(Object tag, String method, JsonObject jsonString, FreeUI_EntityCallBack<T> callBack) {
        RequestBean format = new RequestBean();
        format.setBody(jsonString);
        format.setHeader(new HeaderBean(method));
        BaseRequestBean message = new BaseRequestBean();
        message.setRequest(format);
        Map<String, String> map = new HashMap<>();
        map.put("requestMessage", new Gson().toJson(message));
        Log.e("json", new Gson().toJson(message));
        (((PostRequest)OkGo.post(Constant.REQUEST_URL+"/api/AOSPDA/"+method).tag(tag)).upJson(new Gson().toJson(message))).execute(callBack);
    }
    public static <T> void requestGetNet(Object tag, String method, String url,JsonObject jsonString, FreeUI_EntityCallBack<T> callBack) {
        RequestBean format = new RequestBean();
        format.setBody(jsonString);
        format.setHeader(new HeaderBean(method));
        BaseRequestBean message = new BaseRequestBean();
        message.setRequest(format);
        Map<String, String> map = new HashMap<>();
        map.put("requestMessage", new Gson().toJson(message));
        Log.e("json", new Gson().toJson(message));
        (((PostRequest)OkGo.post(url+method).tag(tag)).upJson(new Gson().toJson(message))).execute(callBack);
    }
}
